package day21.pack8;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/*
  池： 资源的复用。节省开销。
  图书馆：
     西游记    20本
 */
public class Test {
    public static void main(String[] args) {
        Runnable r = ()-> {
            System.out.println("线程任务执行中" + Thread.currentThread().getId());
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("线程任务执行结束" + Thread.currentThread().getId());
        };

        ExecutorService executorService = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 10; i++) {
            executorService.execute(r);
        }
        System.out.println("main end");
    }
}
